package com.example.team.controller;

import com.example.team.entity.Businesstrip;
import com.example.team.service.IBusinesstripService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/***
 * 编写者：王轩
 * 时间：2023/10/30
 * 出差信息管理
 */
@RestController
@Api(tags = "出差信息管理")
public class BusinesstripController {
    @Autowired
    private IBusinesstripService businesstripService;
    @RequestMapping(value = "/Businesstrip",method = {RequestMethod.GET})
    public String Businesstrip(){
        return "出差信息管理系统";
    }
    //添加出差信息申请
    @ApiOperation(value = "添加出差信息申请")
    @RequestMapping(value = "/insterBusinesstrip",method = {RequestMethod.GET})
    public int insterBusinesstrip(Integer EmployeeID,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                                  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date StartDate,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
                                  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date EndDate, String Description, Integer TripID ){
        Businesstrip businesstrip = new Businesstrip();
        businesstrip.setEmployeeID(EmployeeID);
        businesstrip.setStartDate(StartDate);
        businesstrip.setEndDate(EndDate);
        businesstrip.setDescription(Description);
        businesstrip.setTripID(TripID);
        return businesstripService.insertBusinesstrip(businesstrip);
    }
    //审核人签字
    @ApiOperation(value = "审核人签字")
    @RequestMapping(value = "/signBusinesstrip",method = {RequestMethod.GET})
    public int signBusinesstrip(Integer TripID,String Ratifiers){
        Businesstrip businesstrip = new Businesstrip();
        businesstrip.setTripID(TripID);
        businesstrip.setRatifiers(Ratifiers);
        return businesstripService.signBusinesstrip(businesstrip);
    }
    //删除方法
    @ApiOperation(value = "删除出差信息")
    @RequestMapping(value = "/deleteBusinesstrip",method = {RequestMethod.GET})
    public Integer deleteBusinesstrip(Integer businesstripID){
        Businesstrip businesstrip = new Businesstrip();
        businesstrip.setTripID(businesstripID);
        return businesstripService.deleteBusinesstrip(businesstrip);
    }
    //修改方法
    @ApiOperation(value = "修改出差信息")
    @RequestMapping(value = "/updateBusinesstrip",method = {RequestMethod.GET})
    public Integer updateBusinesstrip(Businesstrip businesstrip){
        return businesstripService.updateBusinesstrip(businesstrip);
    }
    //查询方法
    @ApiOperation(value = "查询所有出差信息")
    @RequestMapping(value = "/getAllBusinesstrip",method = {RequestMethod.GET})
    public List<Businesstrip>getAllBusinesstrip(Businesstrip businesstrip){
        return businesstripService.getAllBusinesstrip(businesstrip);
    }
    //根据条件查询
    @ApiOperation(value = "根据条件查询出差信息")
    @RequestMapping(value = "/getBusinesstrip",method = {RequestMethod.GET})
    public Businesstrip getBusinesstrip(Integer businesstripID){
        Businesstrip businesstrip = new Businesstrip();
        businesstrip.setTripID(businesstripID);
        return businesstripService.getBusinesstrip(businesstrip);
    }
}
